package Kolekcje;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

public class TestSet {
	public static void main(String[] args){
		//użycie różnych zbiorów
		Random rnd = new Random();
		HashSet<Integer> hs=new HashSet<Integer>();
		TreeSet<Integer> ts = new TreeSet<Integer>();
		LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
		int a;
		for(int i=0; i<10000; i++){
			a=rnd.nextInt(10);
			hs.add(a);
			ts.add(a);
			lhs.add(a);
		}
		System.out.println("1: "+hs);
		System.out.println("2: "+ts);
		System.out.println("3: "+lhs);
		//metody Set
		System.out.println("\nTest metod Set:");
		Set<String> set1=new HashSet<String>();
		Collections.addAll(set1, "A B C D E F G H I J K L".split(" "));
		set1.add("M");
		System.out.println("H "+set1.contains("H"));
		System.out.println("N "+set1.contains("N"));
		Set<String> set2 = new HashSet<String>();
		Collections.addAll(set2, "H I J K L".split(" "));
		Set<String> set3=new HashSet<String>();
		set3.addAll(set1);
		System.out.println("set1: "+set1);
		System.out.println("set2: "+set2);
		System.out.println("set3: "+set3);
		System.out.println("set2 in set1: "+set1.contains(set2));//zwraca false, czemu?
		System.out.println("set3 in set1: "+set1.contains(set3));//j.w.
		set1.remove("H");
		System.out.println("set1: "+set1);
		System.out.println("set2 in set1: "+set1.contains(set2));
		set1.removeAll(set2);
		System.out.println("set2 usunięty z set1: "+set1);
		Collections.addAll(set1, "X Y Z".split(" "));
		System.out.println("X Y Z dodane do set1: "+set1);
		//generowanie unikatowych list wartości
		System.out.println("\nTest generowania unikatowych wartości:");
		Set<String> words=new TreeSet<String>(new TextFile("/home/ewa/PJWSTK/UTP - Uniweralne Techniki Programowania/Workspace/UTP/src/Kolekcje/TestList.java", "\\W+"));
		System.out.println(words);
		//words.removeAll(Arrays.asList(0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 3, 4, 5, 6, 7, 8, 9));
		Set<String> words2=new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
		words2.addAll(new TextFile("/home/ewa/PJWSTK/UTP - Uniweralne Techniki Programowania/Workspace/UTP/src/Kolekcje/TestList.java", "\\W+"));
		System.out.println(words2);
		
	}
}
